package handler

import (
	"github.com/gin-gonic/gin"
	"regi-med/model"
	"strconv"
)

func List(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	size, _ := strconv.Atoi(c.Query("size"))
	offset := (page - 1) * size
	var total int64
	model.DB.Model(&model.Order{}).Count(&total)
	var order []model.Order
	err := model.DB.Offset(offset).Limit(size).Find(&order).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "查询失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code":  200,
		"msg":   "查询成功",
		"data":  order,
		"total": total,
	})
	return
}
